package com.cuihanyu.newuniversityover.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.RadioGroup;


import com.cuihanyu.newuniversityover.R;
import com.cuihanyu.newuniversityover.adapter.NoScrollViewPagerAdapter;
import com.cuihanyu.newuniversityover.base.BaseFragment;
import com.cuihanyu.newuniversityover.fragment.Books_Fragment;
import com.cuihanyu.newuniversityover.fragment.Home_Fragment;
import com.cuihanyu.newuniversityover.fragment.MiniClass_Fragment;
import com.cuihanyu.newuniversityover.fragment.My_Fragment;
import com.cuihanyu.newuniversityover.customizedview.NoScrollViewPage;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    List<BaseFragment> list;
    private RadioGroup rg;
    private NoScrollViewPage viewPage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (list == null) {
            list = new ArrayList<>();
        }
        initView();
        initData();
    }

    private void initView() {
        viewPage = (NoScrollViewPage) findViewById(R.id.NoScrollViewPage);
        rg = (RadioGroup) findViewById(R.id.rg);
        list.add(new Home_Fragment());
        list.add(new Books_Fragment());
        list.add(new MiniClass_Fragment());
        list.add(new My_Fragment());
        rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (i) {
                    case R.id.home:
                        viewPage.setCurrentItem(0, false);
                        break;
                    case R.id.book:
                        viewPage.setCurrentItem(1, false);
                        break;
                    case R.id.miniclass:
                        viewPage.setCurrentItem(2, false);
                        break;
                    case R.id.my:
                        viewPage.setCurrentItem(3, false);
                        break;
                    default:
                        break;

                }
            }
        });

    }

    private void initData() {
        NoScrollViewPagerAdapter adapter = new NoScrollViewPagerAdapter(getSupportFragmentManager(), list);
        viewPage.setOffscreenPageLimit(4);
        viewPage.setAdapter(adapter);
    }
}
